import * as types from '../../mutation-types'
import lazyLoading from './lazyLoading'

// show: meta.label -> name
// name: component name
// meta.label: display label

const state = {
  items: [
    {
      name: '历史行情',
      path: '/k-line',
      meta: {
        icon: 'fa-bar-chart-o',
        keepAlive: true,
        auth: 'admin'
      },
      component: lazyLoading('k-line/Table')
    }, {
      name: '同步行情',
      path: '/k-line-sync',
      meta: {
        hidden: true,
        icon: 'fa-bar-chart-o',
        keepAlive: true,
        auth: 'admin'
      },
      component: lazyLoading('k-line/Sync')
    }, {
      name: '下载客户端',
      path: '/download-client',
      meta: {
        hidden: true,
        icon: 'fa-download'
      },
      component: lazyLoading('Download')
    }
  ]
}

const mutations = {
  [types.EXPAND_MENU]: function (state, menuItem) {
    if (menuItem.index > -1) {
      if (state.items[menuItem.index] && state.items[menuItem.index].meta) {
        state.items[menuItem.index].meta.expanded = menuItem.expanded
      }
    } else if (menuItem.item && 'expanded' in menuItem.item.meta) {
      menuItem.item.meta.expanded = menuItem.expanded
    }
  }
}

export default {
  state,
  mutations
}
